package com.ybxx.system.service.impl;

import java.util.List;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;
import com.ybxx.system.dao.DataRightsDao;
import com.ybxx.system.model.DataRights;
import com.ybxx.system.model.DataRightsChecked;
import com.ybxx.system.service.DataRightsService;

public class DataRightsServiceImpl extends BaseServiceImpl<DataRights>
		implements DataRightsService {
	DataRightsDao dataRightsDao;
	public DataRightsServiceImpl(DataRightsDao dao){
		super(dao);
		this.dataRightsDao=dao;
	}
	public List<DataRightsChecked> queryDataRights(String loginid){
		String sql="select CONCAT('C',cid) as id,'0' fid,cname as name," +
				"case when b.loginid is null then false else true end as checked " +
				"from tbl_base_community a " +
				"   left join (select * from tbl_system_datarights where dtype='C' and loginid='"+loginid+"') b " +
				"on a.cid=b.dvalue where state='0'" +
				" UNION " +
				"select CONCAT('B',bid) as id,CONCAT('C',cid) as fid,bname as name," +
				"       case when b.loginid is null then false else true end as checked " +
				"from tbl_base_ban a  left join (select * from tbl_system_datarights where dtype='B' and loginid='"+loginid+"') b " +
				"on a.bid=b.dvalue where state='0'" +
				" UNION " +
				"select CONCAT('U',uid) as id,CONCAT('B',bid) as fid,uname as name," +
				"case when b.loginid is null then false else true end as checked " +
				"from tbl_base_unit a " +
				"left join (select * from tbl_system_datarights where dtype='U' and loginid='"+loginid+"') b " +
				"on a.uid=b.dvalue where state='0'" +
				" UNION " +
				"select CONCAT('R',rid) as id,CONCAT('U',uid) as fid,rcode as name," +
				"case when b.loginid is null then false else true end as checked " +
				"from tbl_base_room a " +
				"left join (select * from tbl_system_datarights where dtype='R' and loginid='"+loginid+"') b " +
				"on a.rid=b.dvalue where state='0'";
		return dataRightsDao.queryDataRights("select * from ("+sql+") m order by m.name");
	}
}
